from flask_shop.chartData import chart_data,chart_data_api
from flask_shop import models,db
from flask import request	
from flask_restful import Resource
import re
from flask_shop.utils.message import to_dict_msg
import calendar
import datetime
from datetime import timedelta


# 总阅读量
@chart_data.route('/Total_view',methods=['GET'])
def total_view():
	articles=models.Article.query.all()
	TotalArticle=0
	for a in articles:
		TotalArticle+=a.viewed
	return to_dict_msg(200,TotalArticle,"获取成功")

@chart_data.route('/article_rank',methods=['GET'])
def article_rank():
	articles=models.Article.query.order_by(models.Article.viewed.desc()).limit(10).all()
	alls=[a.to_dict() for a in articles]
	return to_dict_msg(200,alls,"获取成功")
